package com.androidx.p013lv.invention.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AdInfoBean;
import com.androidx.p013lv.base.bean.InventionBean;
import com.androidx.p013lv.base.bean.InventionListBean;
import com.androidx.p013lv.base.bean.RecommendVideoBean;
import com.androidx.p013lv.base.bean.TwoBean;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.OnInventionScrollListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.AdUtils;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.invention.C1069R;
import com.androidx.p013lv.invention.OnInventionType;
import com.androidx.p013lv.invention.adapter.AdapterInventionType;
import com.androidx.p013lv.invention.databinding.FragmentInventionTypeBinding;
import com.gyf.immersionbar.ImmersionBar;
import java.util.List;
import p000a.shuyu.p005a.GSYVideoManager;

/* renamed from: com.androidx.lv.invention.fragment.InventionTypeFragment */
public class InventionTypeFragment extends LazyFragment<FragmentInventionTypeBinding> implements OnInventionType {
    String HTTP_TAG = "queryStations";
    String HTTP_TAG_ONE = "queryBatchVideo";
    String HTTP_TAG_TODAY = "recommendVideo";
    String HTTP_TAG_TWO = "queryBatchMainVideo";
    AdapterInventionType adapter;
    int classifyId;
    boolean isTop = false;
    List<AdInfoBean> list;
    OnInventionScrollListener onListener;
    RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
        /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11401 */

        @Override // androidx.recyclerview.widget.RecyclerView.OnScrollListener
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            super.onScrolled(recyclerView, i, i2);
            if (recyclerView.canScrollVertically(-1)) {
                InventionTypeFragment.this.isTop = true;
            } else if (InventionTypeFragment.this.list != null && InventionTypeFragment.this.list.size() != 0) {
                InventionTypeFragment.this.isTop = false;
            } else {
                return;
            }
            if (InventionTypeFragment.this.onListener != null) {
                InventionTypeFragment.this.onListener.onScrolled(InventionTypeFragment.this.isTop, InventionTypeFragment.this.classifyId);
            }
        }
    };

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment, com.gyf.immersionbar.components.ImmersionOwner
    public void initImmersionBar() {
    }

    public static InventionTypeFragment newInstance(int i, OnInventionScrollListener onInventionScrollListener) {
        Bundle bundle = new Bundle();
        bundle.putInt("type", i);
        InventionTypeFragment inventionTypeFragment = new InventionTypeFragment(onInventionScrollListener);
        inventionTypeFragment.setArguments(bundle);
        return inventionTypeFragment;
    }

    public InventionTypeFragment() {
    }

    public InventionTypeFragment(OnInventionScrollListener onInventionScrollListener) {
        this.onListener = onInventionScrollListener;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        this.classifyId = bundle.getInt("type");
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1069R.C1074layout.fragment_invention_type;
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        GSYVideoManager.onPause();
        OnInventionScrollListener onInventionScrollListener = this.onListener;
        if (onInventionScrollListener != null) {
            onInventionScrollListener.onScrolled(this.isTop, this.classifyId);
        }
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ImmersionBar.getActionBarHeight(this);
        ImmersionBar.getStatusBarHeight(this);
        List<AdInfoBean> homeBanner = AdUtils.getInstance().getHomeBanner(this.classifyId);
        this.list = homeBanner;
        if (homeBanner == null || homeBanner.size() == 0) {
            this.isTop = true;
        }
        ((FragmentInventionTypeBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getContext()));
        this.adapter = new AdapterInventionType(this, this, this.classifyId, 0, this.list);
        ((FragmentInventionTypeBinding) this.binding).recycler.setAdapter(this.adapter);
        ((FragmentInventionTypeBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.View$OnClickListenerC11412 */

            public void onClick(View view) {
                InventionTypeFragment.this.getInfo();
            }
        });
        getInfo();
        ((FragmentInventionTypeBinding) this.binding).recycler.addOnScrollListener(this.onScrollListener);
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (!NetUtil.isNetworkAvailable()) {
            ((FragmentInventionTypeBinding) this.binding).statusLayout.showNoNet();
            return;
        }
        ((FragmentInventionTypeBinding) this.binding).statusLayout.showLoading();
        String queryStations = UrlManager.getInsatance().queryStations(this.classifyId);
        HttpUtils insatance = HttpUtils.getInsatance();
        insatance.get(queryStations, new HttpCallback<BaseRes<InventionListBean>>(this.HTTP_TAG + this.classifyId) {
            /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11423 */

            public void onLvSuccess(BaseRes<InventionListBean> baseRes) {
                InventionTypeFragment inventionTypeFragment;
                if (InventionTypeFragment.this.binding != null && ((FragmentInventionTypeBinding) InventionTypeFragment.this.binding).statusLayout != null && (inventionTypeFragment = InventionTypeFragment.this) != null) {
                    ((FragmentInventionTypeBinding) inventionTypeFragment.binding).statusLayout.hideLoading();
                    if (baseRes.getCode() != 200) {
                        ((FragmentInventionTypeBinding) InventionTypeFragment.this.binding).statusLayout.showError();
                    } else if (baseRes.getData() == null || baseRes.getData().getList() == null || baseRes.getData().getList().size() <= 0) {
                        ((FragmentInventionTypeBinding) InventionTypeFragment.this.binding).statusLayout.showEmpty();
                    } else {
                        int ruleHomeNum = AdUtils.getInstance().getRuleHomeNum(InventionTypeFragment.this.classifyId);
                        if (AdUtils.getInstance().getHomeWeight(InventionTypeFragment.this.classifyId) != null) {
                            int i = 0;
                            for (int i2 = 0; i2 < baseRes.getData().getList().size(); i2++) {
                                if (i == ruleHomeNum) {
                                    baseRes.getData().getList().add(i2, new InventionBean(AdUtils.getInstance().getHomeWeight(InventionTypeFragment.this.classifyId)));
                                    i = 0;
                                } else {
                                    i++;
                                }
                            }
                        }
                        InventionTypeFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                        baseRes.getData().getList().add(0, new InventionBean());
                        baseRes.getData().getList().add(new InventionBean());
                        InventionTypeFragment.this.adapter.setData(baseRes.getData().getList());
                    }
                }
            }
        });
    }

    @Override // com.androidx.p013lv.invention.OnInventionType
    public void onClick(InventionBean inventionBean, int i, int i2) {
        if (!isOnClick()) {
            if (i2 == C1069R.C1072id.btn_more) {
                int type = inventionBean.getType();
                if (type == 1 || type == 2 || type == 12 || type == 13 || type == 20 || type == 18) {
                    ARouter.getInstance().build(Constance.ONE_ACTIVITY).withString(Key.TXT, inventionBean.getStationName()).withInt("type", inventionBean.getStationId()).navigation();
                } else if (type == 3 || type == 4) {
                    ARouter.getInstance().build(Constance.STAR_ACTIVITY).withString(Key.TXT, inventionBean.getStationName()).withInt("type", inventionBean.getStationId()).withInt(Key.STATION_TYPE, inventionBean.getType()).navigation();
                } else if (type == 9) {
                    ARouter.getInstance().build(Constance.TODAY_ACTIVITY).navigation();
                } else if (type == 10) {
                    ARouter.getInstance().build(Constance.VARIETY_ACTIVITY).navigation();
                } else if (type == 11) {
                    ARouter.getInstance().build(Constance.VIDEO_ACTIVITY).navigation();
                } else if (type == 5 || type == 6) {
                    ARouter.getInstance().build(Constance.TOP_ACTIVITY).withInt("type", 0).navigation();
                } else if (type == 14 || type == 15 || type == 16) {
                    ARouter.getInstance().build(Constance.FOURTEEN_ACTIVITY).withString(Key.TXT, inventionBean.getStationName()).withInt("type", inventionBean.getStationId()).navigation();
                } else if (type == 17) {
                    ARouter.getInstance().build(Constance.NEW_ONE_ACTIVITY).withString(Key.TXT, inventionBean.getStationName()).withInt("type", inventionBean.getStationId()).withInt(Key.STATION_TYPE, inventionBean.getType()).navigation();
                }
            } else if (i2 == C1069R.C1072id.btn_swap) {
                int type2 = inventionBean.getType();
                if (type2 == 2) {
                    swapTwo(inventionBean, i);
                } else if (type2 == 1) {
                    swapOne(inventionBean, i);
                } else if (type2 == 13) {
                    swapThirteen(inventionBean, i);
                } else if (type2 == 14) {
                    swapFourteen(inventionBean, i);
                } else if (type2 == 15) {
                    swapFifteen(inventionBean, i);
                }
            } else if (i2 == C1069R.C1072id.btn_day_before) {
                dayBefore(inventionBean.getRecAt(), i);
            } else if (i2 == C1069R.C1072id.ll_item) {
                ARouter.getInstance().build(Constance.VIDEO_ACTIVITY).withSerializable("data", inventionBean.getBrushVideo()).navigation();
            }
        }
    }

    public void dayBefore(String str, final int i) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().recommendVideo(str, 2), new HttpCallback<BaseRes<RecommendVideoBean>>(this.HTTP_TAG_TODAY, getContext()) {
            /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11434 */

            public void onLvSuccess(BaseRes<RecommendVideoBean> baseRes) {
                if (baseRes.getCode() != 200) {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                } else if (baseRes.getData() == null || baseRes.getData().getData() == null || baseRes.getData().getData().size() <= 0) {
                    ToastUtils.getInstance().showSigh("前壹天沒有更多數據...");
                } else {
                    ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setDailyRecResList(baseRes.getData().getData());
                    ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setRecAt(baseRes.getData().getRecAt());
                    InventionTypeFragment.this.adapter.notifyItemChanged(i);
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void swapOne(InventionBean inventionBean, final int i) {
        if (inventionBean.getVideoList() != null && inventionBean.getVideoList().size() != 0) {
            String queryBatchVideo = UrlManager.getInsatance().queryBatchVideo(inventionBean.getStationId(), 6, inventionBean.getVideoList().get(inventionBean.getVideoList().size() - 1).getVideoId());
            HttpUtils insatance = HttpUtils.getInsatance();
            insatance.get(queryBatchVideo, new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG_ONE + this.classifyId, getContext()) {
                /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11445 */

                public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setVideoList(baseRes.getData().getList());
                        InventionTypeFragment.this.adapter.notifyItemChanged(i);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            });
        }
    }

    /* access modifiers changed from: package-private */
    public void swapTwo(InventionBean inventionBean, final int i) {
        if (inventionBean.getListMainVideoResp().getMainVideo() != null && inventionBean.getListMainVideoResp().getMainVideo().size() != 0 && inventionBean.getListMainVideoResp().getList() != null && inventionBean.getListMainVideoResp().getList().size() != 0) {
            List<VideoBean> list2 = inventionBean.getListMainVideoResp().getList();
            String queryBatchMainVideo = UrlManager.getInsatance().queryBatchMainVideo(inventionBean.getStationId(), inventionBean.getListMainVideoResp().getMainVideo().get(0).getSortNum(), list2.get(list2.size() - 1).getVideoId());
            HttpUtils insatance = HttpUtils.getInsatance();
            insatance.get(queryBatchMainVideo, new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG_TWO + this.classifyId, getContext()) {
                /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11456 */

                public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setListMainVideoResp(baseRes.getData());
                        InventionTypeFragment.this.adapter.notifyItemChanged(i);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            });
        }
    }

    /* access modifiers changed from: package-private */
    public void swapThirteen(InventionBean inventionBean, final int i) {
        if (inventionBean.getVideoList() != null && inventionBean.getVideoList().size() != 0) {
            String queryBatchVideo = UrlManager.getInsatance().queryBatchVideo(inventionBean.getStationId(), 4, inventionBean.getVideoList().get(inventionBean.getVideoList().size() - 1).getVideoId());
            HttpUtils insatance = HttpUtils.getInsatance();
            insatance.get(queryBatchVideo, new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG_ONE + this.classifyId, getContext()) {
                /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11467 */

                public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setVideoList(baseRes.getData().getList());
                        InventionTypeFragment.this.adapter.notifyItemChanged(i);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            });
        }
    }

    /* access modifiers changed from: package-private */
    public void swapFourteen(InventionBean inventionBean, final int i) {
        if (inventionBean.getVideoList() != null && inventionBean.getVideoList().size() != 0) {
            String queryBatchVideo = UrlManager.getInsatance().queryBatchVideo(inventionBean.getStationId(), 4, inventionBean.getVideoList().get(inventionBean.getVideoList().size() - 1).getVideoId());
            HttpUtils insatance = HttpUtils.getInsatance();
            insatance.get(queryBatchVideo, new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG_ONE + this.classifyId, getContext()) {
                /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11478 */

                public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setVideoList(baseRes.getData().getList());
                        InventionTypeFragment.this.adapter.notifyItemChanged(i);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            });
        }
    }

    /* access modifiers changed from: package-private */
    public void swapFifteen(InventionBean inventionBean, final int i) {
        if (inventionBean.getVideoList() != null && inventionBean.getVideoList().size() != 0) {
            String queryBatchVideo = UrlManager.getInsatance().queryBatchVideo(inventionBean.getStationId(), 6, inventionBean.getVideoList().get(inventionBean.getVideoList().size() - 1).getVideoId());
            HttpUtils insatance = HttpUtils.getInsatance();
            insatance.get(queryBatchVideo, new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG_ONE + this.classifyId, getContext()) {
                /* class com.androidx.p013lv.invention.fragment.InventionTypeFragment.C11489 */

                public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        ((InventionBean) InventionTypeFragment.this.adapter.getDataInPosition(i)).setVideoList(baseRes.getData().getList());
                        InventionTypeFragment.this.adapter.notifyItemChanged(i);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            });
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils insatance = HttpUtils.getInsatance();
        insatance.cancelTag(this.HTTP_TAG + this.classifyId);
        HttpUtils insatance2 = HttpUtils.getInsatance();
        insatance2.cancelTag(this.HTTP_TAG_ONE + this.classifyId);
        HttpUtils insatance3 = HttpUtils.getInsatance();
        insatance3.cancelTag(this.HTTP_TAG_TWO + this.classifyId);
    }
}
